package com.example.zhiran.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.regex.Pattern;


public class StringUtil {
    private static ObjectMapper mapper = new ObjectMapper();
    //手机号正则表达式
    private static final String REGEX_TEL = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(16[5,6])|(17[0-8])|(18[0-9])|(19[1,5,8,9]))\\d{8}$";


    public static boolean isTel(String tel){
        Pattern pattern = Pattern.compile(REGEX_TEL);
        return pattern.matcher(tel).matches();
    }

    public static String objectToJson(Object obj){
        if (obj==null){
            return "";
        }
        String jsonString = "";
        try {
            jsonString = mapper.writeValueAsString(obj);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return jsonString;
    }
}
